import { FC, useState } from 'react';
import styled from "@emotion/styled";
import { LoginPage } from './login';
import { RegisterPage } from './register';
import left from "assets/left.svg";
import right from "assets/right.svg";

export const UnauthenticatedApp: FC = ({ children }) => {
  const [isRegister, setIsRegister] = useState(false);
  const [error, setError] = useState<Error | null>(null);

  return (
    <Container>
      <Header />
      <ShadowCard>
        <Title>{isRegister ? "请注册" : "请登录"}</Title>
        <div style={{ color: 'red' }}>{error?.message}</div>
        {isRegister ? <RegisterPage onError={setError} /> : <LoginPage onError={setError} />}
        <button type="button" onClick={() => setIsRegister(!isRegister)}>
          {isRegister ? "已经有账号了？直接登录" : "没有账号？注册新账号"}
        </button>
      </ShadowCard>
    </Container>
  );
}

export const LongButton = styled.button`
  width: 100%;
`;

const Title = styled.h2`
  margin-bottom: 2.4rem;
  color: rgb(94, 108, 132);
`;

const Background = styled.div`
  position: absolute;
  width: 100%;
  height: 100%;
`;

const Header = styled.header`
  padding: 5rem 0;
  background-size: 8rem;
  width: 100%;
`;

const ShadowCard = styled.div`
  padding: 3.2rem 4rem;
  border-radius: 0.3rem;
  box-sizing: border-box;
  box-shadow: rgba(0, 0, 0, 0.1) 0 0 10px;
  text-align: center;
`;

const Container = styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
`;